package day03.acc

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author wsl
 * @Description  Kryo速度是Serializable的10倍
 */
object Serializable03 {
  def main(args: Array[String]): Unit = {

    // 替换默认的java序列化机制
    val conf: SparkConf = new SparkConf().setAppName("s3 ").setMaster("local[*]")
      .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      // 注册需要使用kryo序列化的自定义类
      .registerKryoClasses(Array(classOf[Search]))

    val sc = new SparkContext(conf)

    val rdd: RDD[String] = sc.makeRDD(Array("hello world", "hello atguigu", "atguigu", "hahah"), 2)

    val search = new Search("hello")
    search.getMatch1(rdd).collect.foreach(println)

    sc.stop()
  }
}

